package rpc.provider.consumer.consumer;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.oracle.webservices.internal.api.databinding.DatabindingMode;
import org.apache.commons.lang.StringUtils;
import rpc.provider.consumer.SoaErrorEnum;
import rpc.provider.consumer.SoaResponse;
import rpc.provider.consumer.third.UserQueryThirdService;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author: cuiyutian1
 * @date: 2021/9/4 13:11
 * @description:
 */
public class UserQueryConsumer {

    public static void main(String[] args) throws JsonProcessingException {


        System.out.println(StringUtils.isBlank(null));


        UserQueryThirdService thirdService = new UserQueryThirdService();
        SoaResponse<String> response = thirdService.UserQuery();
        ObjectMapper mapper = new ObjectMapper();
        String value = mapper.writeValueAsString(response);
        System.out.println(value);

        person person1 = new person();
        person1.name = "111";

        person person2 = new person();
        person2.name = "222";

        person person3 = new person();
        person3.name = "333";

        person person4 = new person();
        person4.name = "111";

        ArrayList<person> peoples = new ArrayList<>();
        peoples.add(person1);
        peoples.add(person2);
        peoples.add(person3);
        peoples.add(person4);


        List<person> collect = peoples.stream().filter((item) -> {
            String name = item.name;
            return "111".equals(name);
        }).collect(Collectors.toList());

        collect.forEach(System.out::println);

        Iterator<person> iterator = peoples.iterator();
        while (iterator.hasNext()){
            person people = iterator.next();
            if("111".equals(people.name)){
                people.name ="modify";
                iterator.remove();
            }
        }

//        for (person people : peoples) {
//            if("111".equals(people.name)){
//                people.name ="modify";
//                peoples.remove(people);
//            }
//        }

        System.out.println(peoples.size());
        peoples.forEach(System.out::println);
    }

    static class person{
        String name;

        @Override
        public String toString() {
            return "person{" +
                    "name='" + name + '\'' +
                    '}';
        }
    }
}
